#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>


int main(){

	pid_t pid;
	int cnt = 0;

	
	printf("this is before pid =%d\n",getpid());

	pid = fork();
	
	if(pid == -1){
		printf("creat process failed\n");
	}
	else if(pid > 0){
		
		wait(NULL);	
		while(1){
			printf("this is father process ,pid = %d\n",getpid());
			sleep(2);
			printf("cnt = %d\n",cnt);
		}
	}
	else if(pid == 0){
		while(1){
			printf("this is child process,pid = %d\n",getpid());
			sleep(2);
			cnt++;
			if(cnt == 3){
				exit(0);
			}
		}
	}
	return 0;
}
